<?php 

function dateValid($date=null)
{
	//buat array nama hari dalam bahasa Indonesia dengan urutan 1-7
	$array_hari = array(1=>'Senin','Selasa','Rabu','Kamis','Jumat', 'Sabtu','Minggu');
	//buat array nama bulan dalam bahasa Indonesia dengan urutan 1-12
	$array_bulan = array(1=>'Januari','Februari','Maret', 'April', 'Mei', 'Juni','Juli','Agustus',
					'September','Oktober', 'November','Desember');
	
	if ($date == '0000-00-00' || $date == '1970-01-01' || $date == null ){
		return "";
	} else {
		//jika $date diisi, makan tanggal yang diformat adalah tanggal tersebut
		$date  = strtotime($date);
		$hari  = $array_hari[date('N',$date)];
		$tanggal = date ('j', $date);
		$bulan = $array_bulan[date('n',$date)];
		$tahun = date('Y',$date);
		$formatTanggal = $tanggal ." ". $bulan ." ". $tahun;
		return $formatTanggal;
	}
}if(@$type!=="excel") { ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Hasil Tender</title>
<?php echo css_asset("printstyle.css"); ?>
</head>
<body>
<?php } else { ?>
<html xmlns:o="urn:schemas-microsoft-com:office:office"
                                       xmlns:x="urn:schemas-microsoft-com:office:excel"
                                        xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Laporan Hasil Tender</title>
<style>
.table{
        border-collapse:collapse;      
}
</style>
<xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet</x:Name>
    <x:WorksheetOptions>
     <x:Print>
        <x:Gridlines />
     </x:Print>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
 </x:ExcelWorkbook>
</xml>
</head>
<body>
<?php } 
if (count($data_print) > 0 ) {
?>
	<h3><center>LAPORAN HASIL TENDER <?php echo strtoupper($data_print[0]->cabang_nama)." TAHUN ".$tahun; ?></center></h3>
	<small>CABANG : <?php echo latinToRomawi(str_replace("CABANG ","",$data_print[0]->cabang_nama)); ?><br>
	DVO : III<br>
	&nbsp;
	</small>
<table summary='Laporan Hasil Tender' width="100%" class="print">
	<thead>
		<tr>
			<th scope='col' rowspan=2>No</th>
			<th scope='col' rowspan=2>Tanggal</th>
			<th scope='col' rowspan=2>Nama Proyek</th>
			<th scope='col' rowspan=2>Nama Owner</th>
			<th scope='col' colspan=2>Penawaran <br />(Rp.)</th>
			<th scope='col' colspan=4>Hasil Tender / Pemenang</th>
			<th scope='col' rowspan=2>Remark</th>
			<!-- th scope='col' colspan=9>Keterangan</th -->
		</tr>
		<tr>
			<th scope='col' >Harga</th>
			<th scope='col' >Harga - PPN</th>
			<th scope='col' >Menang</th>
			<th scope='col' >Kalah Harga dll</th>
			<th scope='col' >Kalah HP</th>
			<th scope='col' >Blm Diputuskan</th>
			<!-- th scope='col' >UND</th>
			<th scope='col' >DOK<br>LLG</th>
			<th scope='col' >CR</th>
			<th scope='col' >MR</th>
			<th scope='col' >Kontrak</th>
			<th scope='col' >BoQ</th>
			<th scope='col' >RKS</th>
			<th scope='col' >GBR</th>
			<th scope='col' >&nbsp;</th -->
		</tr>
	</thead>
	<tbody>
	<?php
	
	$jumlah_tender_nk = array(0,0,0);
	$jumlah_tender_menang = array(0,0,0);
	$jumlah_tender_kalahdll = array(0,0,0); 
	$jumlah_tender_kalah = array(0,0,0); 
	$jumlah_tender_belum = array(0,0,0);
	
	$jumlah_ikut_menang = array(0,0,0);
	$jumlah_ikut_kalahdll = array(0,0,0); 
	$jumlah_ikut_kalah = array(0,0,0); 
	$jumlah_ikut_belum = array(0,0,0);
	
	$i=0; foreach($data_print as $print) { $i++;
	$menang = 0; $kalahdll= 0; $kalah= 0; $belum = 0;
	$menang_count =  0; $kalahdll_count = 0; $kalah_count = 0; $belum_count =  0;
	$status = "";
	switch($print->jadwal_status){
		case "Menang" : $status = " style='color:#00A2E8' "; break;
		case "Kalah Harga dll" : $status = " style='color:#f00' "; break;
		case "Kalah HP" : $status = " style='color:#800080' "; break;
		default : $status = " style='color:#0b0' ";
	}
	
	?>
	<tr <?php echo $status ; ?>><td><?php echo $i ; ?></td>
	<td><?php echo dateValid($print->tanggal) ; ?></td>
	<td><?php echo $print->jadwal_namaproyek  ; ?></td>
	<td><?php echo $print->owner_jenis  ; ?></td>
	<td style="text-align:right"><?php echo number_format($print->jadwal_nk,0,",","."); ?></td>
	<td style="text-align:right"><?php echo number_format($print->jadwal_nk * (100/110),0,",","."); ?></td>
	<td style="text-align:right"><?php if ( $print->jadwal_status == "Menang" ) {$menang_count = 1;$menang = $print->jadwal_nk  * (100/110); echo number_format($print->jadwal_nk  * (100/110),0,",",".")  ; } ?></td>
	<td style="text-align:right"><?php if ( $print->jadwal_status == "Kalah Harga dll" ){ $kalahdll_count = 1; $kalahdll = $print->jadwal_nk  * (100/110); echo number_format($print->jadwal_nk  * (100/110),0,",",".")  ; } ?></td>
	<td style="text-align:right"><?php if ( $print->jadwal_status == "Kalah HP" ) {$kalah_count = 1;$kalah = $print->jadwal_nk  * (100/110); echo number_format($print->jadwal_nk  * (100/110),0,",",".")  ;  } ?></td>
	<td style="text-align:right"><?php if ( $print->jadwal_status == "" OR $print->jadwal_status == "-" ) {$belum_count = 1;$belum = $print->jadwal_nk  * (100/110); echo number_format($print->jadwal_nk  * (100/110),0,",",".")  ;} ?></td>
	<!-- td><?php if ($print->jadwal_flagundangan == "Y") echo "V"; else echo "-"; ?></td>
	<td><?php if ( $print->jadwal_flagllg == "Y") echo "V"; else echo "-"; ?></td>
	<td><?php if ( $print->jadwal_flagcr == "Y") echo "V"; else echo "-"; ?></td>
	<td><?php if ( $print->jadwal_flagmr == "Y") echo "V"; else echo "-"; ?></td>
	<td><?php if ( dateValid($print->jadwal_tglkontrak) != "") echo "V"; else echo "-"; ?></td>
	<td><?php if ( $print->jadwal_flagboq == "Y") echo "V"; else echo "-"; ?></td>
	<td><?php if ( $print->jadwal_flaqrks == "Y") echo "V"; else echo "-"; ?></td>
	<td><?php if ( $print->jadwal_flaggbr == "Y") echo "V"; else echo "-"; ?></td>
	<td>&nbsp;</td -->
	<td><?php echo $print->jadwal_remkontrak  ; ?></td>
	</tr>
	<?php  
	switch ($print->owner_jenis){
		case "BUMN" : 
			$jumlah_tender_nk[0] = $jumlah_tender_nk[0] + $print->jadwal_nk;
			$jumlah_tender_menang[0] =$jumlah_tender_menang[0] + $menang;
			$jumlah_tender_kalahdll[0] =$jumlah_tender_kalahdll[0] + $kalahdll;
			$jumlah_tender_kalah[0] = $jumlah_tender_kalah[0] +$kalah;
			$jumlah_tender_belum[0] = $jumlah_tender_belum[0] +$belum;
			
			$jumlah_ikut_menang[0] = $jumlah_ikut_menang[0] + $menang_count;
			$jumlah_ikut_kalahdll[0] =$jumlah_ikut_kalahdll[0] + $kalahdll_count ;
			$jumlah_ikut_kalah[0] = $jumlah_ikut_kalah[0]  + $kalahdll_count ;
			$jumlah_ikut_belum[0] = $jumlah_ikut_belum[0] + $belum_count;
		break;
		case "PEMERINTAH" : 
			$jumlah_tender_nk[1] = $jumlah_tender_nk[1] + $print->jadwal_nk;
			$jumlah_tender_menang[1] =$jumlah_tender_menang[1] + $menang;
			$jumlah_tender_kalahdll[1] =$jumlah_tender_kalahdll[1] + $kalahdll;
			$jumlah_tender_kalah[1] = $jumlah_tender_kalah[1] +$kalah;
			$jumlah_tender_belum[1] = $jumlah_tender_belum[1] +$belum;
			
			$jumlah_ikut_menang[1] = $jumlah_ikut_menang[1] + $menang_count;
			$jumlah_ikut_kalahdll[1] =$jumlah_ikut_kalahdll[1] + $kalahdll_count ;
			$jumlah_ikut_kalah[1] = $jumlah_ikut_kalah[1]  + $kalahdll_count ;
			$jumlah_ikut_belum[1] = $jumlah_ikut_belum[1] + $belum_count;
			break;
		case "SWASTA" : 
			$jumlah_tender_nk[2] = $jumlah_tender_nk[2] + $print->jadwal_nk;
			$jumlah_tender_menang[2] =$jumlah_tender_menang[2] + $menang;
			$jumlah_tender_kalahdll[2] =$jumlah_tender_kalahdll[2] + $kalahdll;
			$jumlah_tender_kalah[2] = $jumlah_tender_kalah[2] +$kalah;
			$jumlah_tender_belum[2] = $jumlah_tender_belum[2] +$belum;
			
			$jumlah_ikut_menang[2] = $jumlah_ikut_menang[2] + $menang_count;
			$jumlah_ikut_kalahdll[2] =$jumlah_ikut_kalahdll[2] + $kalahdll_count ;
			$jumlah_ikut_kalah[2] = $jumlah_ikut_kalah[2]  + $kalahdll_count ;
			$jumlah_ikut_belum[2] = $jumlah_ikut_belum[2] + $belum_count;
			break;
	}
	} ?>
	</tbody>
	<tfoot>
		<tr><th scope='row' colspan=4>JUMLAH TENDER BUMN</th>
			
			<td style="text-align:right"><?php echo number_format($jumlah_tender_nk[0],0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_nk[0] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_menang[0]  * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_kalahdll[0]  * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_kalah[0]  * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_belum[0]  * (100/110),0,",","."); ?></td>
			<td>&nbsp;</td>
		</tr>
		<tr><th scope='row' colspan=4>JUMLAH TENDER PEMERINTAH</th>
			
			<td style="text-align:right"><?php echo number_format($jumlah_tender_nk[1],0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_nk[1] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_menang[1] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_kalahdll[1] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_kalah[1] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_belum[1] * (100/110),0,",","."); ?></td>
			<td>&nbsp;</td>
		</tr>
		<tr><th scope='row' colspan=4>JUMLAH TENDER SWASTA</th>
			
			<td style="text-align:right"><?php echo number_format($jumlah_tender_nk[2],0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_nk[2] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_menang[2] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_kalahdll[2] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_kalah[2] * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format($jumlah_tender_belum[2] * (100/110),0,",","."); ?></td>
			<td>&nbsp;</td>
		</tr>
		<tr  style="border-top:2px solid #000"><th scope='row' colspan=4>Sub Total</th>
			
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td style="text-align:right"><?php echo number_format(array_sum($jumlah_tender_menang) * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format(array_sum($jumlah_tender_kalahdll) * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format(array_sum($jumlah_tender_kalah) * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php echo number_format(array_sum($jumlah_tender_belum) * (100/110),0,",","."); ?></td>
			<td style="text-align:right"><?php 
				$nilaikontrak = array_sum($jumlah_tender_menang) +
				array_sum($jumlah_tender_kalahdll) +
				array_sum($jumlah_tender_kalah) +
				array_sum($jumlah_tender_belum) ;
				
				echo number_format( (
				array_sum($jumlah_tender_menang) +
				array_sum($jumlah_tender_kalahdll) +
				array_sum($jumlah_tender_kalah) +
				array_sum($jumlah_tender_belum) )  * (100/110) 
				,0,",",".");  ?></td>
		</tr>
		<tr><td colspan=11>&nbsp;</td></tr>
		<tr  ><th scope='row' colspan=4>PROSENTASE TERHADAP NILAI KONTRAK</th>
			
			
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td style="text-align:right"><?php if ($nilaikontrak == 0 || $nilaikontrak == "") echo 0; else echo round((array_sum($jumlah_tender_menang) * 100 ) / $nilaikontrak,2); ?>%</td>
			<td style="text-align:right"><?php if ($nilaikontrak == 0 || $nilaikontrak == "") echo 0; else  echo round((array_sum($jumlah_tender_kalahdll) * 100 ) / $nilaikontrak,2); ?>%</td>
			<td style="text-align:right"><?php if ($nilaikontrak == 0 || $nilaikontrak == "") echo 0; else  echo round((array_sum($jumlah_tender_kalah) * 100 ) / $nilaikontrak,2); ?>%</td>
			<td style="text-align:right"><?php if ($nilaikontrak == 0 || $nilaikontrak == "") echo 0; else  echo round((array_sum($jumlah_tender_belum) * 100 ) / $nilaikontrak,2); ?>%</td>
			<td style="text-align:right"><?php if ($nilaikontrak == 0 || $nilaikontrak == "") echo 0; else  echo round(($nilaikontrak * 100 ) / $nilaikontrak,2); ?>%</td>
		</tr>
		<tr ><th scope='row' colspan=4>JUMLAH YANG DIIKUTI</th>
			
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td style="text-align:right"><?php echo array_sum($jumlah_ikut_menang); ?></td>
			<td style="text-align:right"><?php echo array_sum($jumlah_ikut_kalahdll); ?></td>
			<td style="text-align:right"><?php echo array_sum($jumlah_ikut_kalah); ?></td>
			<td style="text-align:right"><?php echo array_sum($jumlah_ikut_belum); ?></td>
			<td style="text-align:right"><?php 
				$jumlahikut = array_sum($jumlah_ikut_menang) +
				array_sum($jumlah_ikut_kalahdll) +
				array_sum($jumlah_ikut_kalah) +
				array_sum($jumlah_ikut_belum) ;
				
				echo number_format(
				array_sum($jumlah_ikut_menang) +
				array_sum($jumlah_ikut_kalahdll) +
				array_sum($jumlah_ikut_kalah) +
				array_sum($jumlah_ikut_belum) 
				,0,",","."); ?></td>
		</tr>
		<tr ><th scope='row' colspan=4>PROSENTASE TERHADAP JUMLAH YANG DIIKUTI</th>
			
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td style="text-align:right"><?php if ($jumlahikut == 0 || $jumlahikut == "") echo 0; else  echo round((array_sum($jumlah_ikut_menang) * 100 ) / $jumlahikut,2); ?>%</td>
			<td style="text-align:right"><?php if ($jumlahikut == 0 || $jumlahikut == "") echo 0; else  echo round((array_sum($jumlah_ikut_kalahdll) * 100 ) / $jumlahikut,2); ?>%</td>
			<td style="text-align:right"><?php if ($jumlahikut == 0 || $jumlahikut == "") echo 0; else  echo round((array_sum($jumlah_ikut_kalah) * 100 ) / $jumlahikut,2); ?>%</td>
			<td style="text-align:right"><?php if ($jumlahikut == 0 || $jumlahikut == "") echo 0; else  echo round((array_sum($jumlah_ikut_belum) * 100 ) / $jumlahikut,2); ?>%</td>
			<td style="text-align:right"><?php if ($jumlahikut == 0 || $jumlahikut == "") echo 0; else  echo round(($jumlahikut * 100 ) / $jumlahikut,2); ?>%</td>
		</tr>
		
		<tr><td colspan=11  style="border-top:2px solid #000">&nbsp;</td></tr>
		
		<tr>  <th scope='row' colspan=4 style="text-align:center">MENANG PORSI BUMN</th>
			
			<!-- td style="text-align:right"><?php echo ($jumlah_ikut_menang[0]+ $jumlah_ikut_kalahdll[0] + $jumlah_ikut_kalah[0] + $jumlah_ikut_belum[0]); ?> Tender</td>
			--> <td style="text-align:right"><?php echo ($jumlah_ikut_menang[0]); ?> Tender</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
		
		<tr   ><th scope='row' colspan=4 style="text-align:center">MENANG PORSI PEMERINTAH</th>
			
			<!-- td style="text-align:right"><?php echo ($jumlah_ikut_menang[1]+ $jumlah_ikut_kalahdll[1] + $jumlah_ikut_kalah[1] + $jumlah_ikut_belum[1]); ?> Tender</td>
			--><td style="text-align:right"><?php echo ($jumlah_ikut_menang[1]); ?> Tender</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
		<tr ><th scope='row' colspan=4 style="text-align:center">MENANG PORSI SWASTA</th>
			
			<!-- td style="text-align:right"><?php echo ($jumlah_ikut_menang[2]+ $jumlah_ikut_kalahdll[2] + $jumlah_ikut_kalah[2] + $jumlah_ikut_belum[2]); ?> Tender</td -->
			<td style="text-align:right"><?php echo ($jumlah_ikut_menang[2]); ?> Tender</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
			<td>&nbsp;</td>
		</tr>
	</tfoot>
	</table>
	
	<?php  }else{ ?>
		<center><b>Tidak ada data yang ditemukan!</b></center>
		<?php } ?>
</body> 
</html>